package com.fuyao.cloud.asset.inventory.process;

import com.fuyao.cloud.common.core.util.SpringContextHolder;

import java.util.Map;

/**
 * 初始化策略上下文对象
 *
 * @author liyue
 * @date 2022年8月11日
 */
public final class HandlerInventoryTaskTypeContext {
    private Map<String, Class> handlerMap;

    public HandlerInventoryTaskTypeContext(Map<String, Class> handlerMap) {
        this.handlerMap = handlerMap;
    }

    public InventoryTaskTypeFactory getInstance(String inventoryTaskType) {
        Class clazz = handlerMap.get(inventoryTaskType);
        if (clazz == null) {
            throw new IllegalArgumentException("not found handler for InventoryTaskType:" + inventoryTaskType);
        }
        return (InventoryTaskTypeFactory)SpringContextHolder.getBean(clazz);
    }
}
